/*
 * packet_gen.h
 *
 *  Created on: 2011-07-01
 *      Author: Shah
 */

#ifndef PACKET_GEN_H_
#define PACKET_GEN_H_


//no overloading in C???
char* packet_gen2(int, char);  //repeat a given char multiple times; int parameter= packet size in bits
char* packet_gen(int);	//generate random characters; int parameter= packet size in bits

char* packet_gen(int pkt_size)
{
	int i=0;
	char *dst= (char*) malloc((pkt_size/8)+2);
	char *str=dst;
	for (i=0;i<(pkt_size/8)+1; i++)
	{
		*dst=(rand() % 0xFE) +1;
		char temp=*dst;
		if((temp << 4)==0)
			*dst++;
		dst++;
	}
	*dst='\0';

	return str;
}

char* packet_gen2(int pkt_size, char byte)
{
	int i=0;
	char *dst= (char*) malloc((pkt_size/8)+2);
	char *str=dst;
	for (i=0;i<(pkt_size/8)+1; i++)
	{
		*dst=byte;
		dst++;
	}
	*dst='\0';

	return str;
}

#endif /* PACKET_GEN_H_ */
